package com.tenglong.teacher.ui.adapter;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.tenglong.teacher.R;
import com.tenglong.teacher.data.resultInfo.InfomMessageInfo;
import com.tenglong.teacher.data.resultInfo.MessageInfo;
import com.tenglong.teacher.ui.adapter.viewholder.InformViewHolder;
import com.tenglong.teacher.ui.adapter.viewholder.VerifyMessageViewHolder;
import com.tenglong.teacher.ui.adapter.viewholder.base.BaseViewHolder;

import java.util.List;


/**
 * @author hdx on 2019/3/27.
 */
public class MessageAdapter extends RecyclerView.Adapter<BaseViewHolder<MessageInfo>> {

    private List<MessageInfo> messageInfos;
    private MessageListener listener;

    public MessageAdapter(List<MessageInfo> messageInfos) {
        this.messageInfos = messageInfos;
    }

    @NonNull
    @Override
    public BaseViewHolder<MessageInfo> onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        switch (viewType) {
            case 0:
                return new InformViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_inform_message_layout, parent, false), listener, this);
            default:
                return new VerifyMessageViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_verify_message_layout, parent, false), listener, this);
        }
    }

    @Override
    public void onBindViewHolder(@NonNull BaseViewHolder<MessageInfo> holder, int position) {
        holder.setLayoutInfo(messageInfos.get(position));
    }

    @Override
    public int getItemViewType(int position) {
        MessageInfo info = messageInfos.get(position);
        if (info instanceof InfomMessageInfo) {
            return 0;
        } else {
            return 1;
        }
    }

    public List<MessageInfo> getMessageInfos() {
        return messageInfos;
    }

    @Override
    public int getItemCount() {
        return messageInfos.size();
    }

    public void setMessageListener(MessageListener listener) {
        this.listener = listener;
    }

    public interface MessageListener {
        void onInformListener(int position);
        void onVerifyMessageEvent(int position,boolean isAgree);
    }
}
